local skel = fk.CreateSkill {
  name = "emo__jianbu",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__jianbu"] = "键哺",
  [":emo__jianbu"] = "锁定技，你的体力上限与手牌上限等于存活角色数。",
}

skel:addEffect(fk.BeforeMaxHpChanged, {
  can_trigger = function(self, event, target, player, data)
    if (not player:hasSkill(skel.name)) or (player.room:getBanner("RoundCount") == nil)
    or player:usedSkillTimes(skel.name, Player.HistoryPhase) > 20 then return false end
    local n = #player.room.alive_players
    return target == player and (player.maxHp + data.num) ~= n
  end,
  on_use = function(self, event, target, player, data)
    data.num = #player.room.alive_players - player.maxHp
  end,
})

skel:addEffect(fk.GameStart, {
  can_trigger = function(self, event, target, player, data)
    if (not player:hasSkill(skel.name)) or (player.room:getBanner("RoundCount") == nil)
    or player:usedSkillTimes(skel.name, Player.HistoryPhase) > 20 then return false end
    return player.maxHp ~= #player.room.alive_players
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, #room.alive_players - player.maxHp)
  end,
})

skel:addEffect(fk.Deathed, {
  can_trigger = function(self, event, target, player, data)
    if (not player:hasSkill(skel.name)) or (player.room:getBanner("RoundCount") == nil)
    or player:usedSkillTimes(skel.name, Player.HistoryPhase) > 20 then return false end
    return player.maxHp ~= #player.room.alive_players
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, #room.alive_players - player.maxHp)
  end,
})

skel:addEffect(fk.EventAcquireSkill, {
  can_trigger = function(self, event, target, player, data)
    if (not player:hasSkill(skel.name)) or (player.room:getBanner("RoundCount") == nil)
    or player:usedSkillTimes(skel.name, Player.HistoryPhase) > 20 then return false end
    return player.maxHp ~= #player.room.alive_players
    and data.skill.name == skel.name and target == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, #room.alive_players - player.maxHp)
  end,
})

skel:addEffect("maxcards", {
  fixed_func = function(self, player)
    if player:hasSkill(skel.name) then
      return player.maxHp
    end
  end
})

return skel
